<?php

namespace App\Http\Services;

use App\Http\Model\CustomGame;

class CustomServices extends CommonServices
{
    protected $customModel;
    protected $finance_service;

    public function __construct()
    {
        parent::__construct();
        $this->customModel = new CustomGame();
        $this->finance_service = new FinanceServices();
    }
    
    //发放人气票
    public function SendTicket($userId, $needNum, $price, $type=3){
        //活动模版人气票展示条件
        $customInfo = $this->customModel->getCumstomInfo($userId);
        $start = $customInfo['start_act'];
        $end = $customInfo['end_act'];
        //获取后台配置消耗钻石数=1人气票
        $gameConfig = $this->customModel->getCustomTicketConfig();
        $costValue = isset($gameConfig['cost_value']) ? $gameConfig['cost_value'] : 10;

        $costDiamond = $price * $needNum;
        $ticketNums = intval($costDiamond/$costValue); 
        if(time() >= $start && time() <= $end){
            $ticketNums = 0-$ticketNums;
            $this->finance_service->newYearGiftNumChange($userId, 226, $ticketNums, $type);
        }
        return true;
    }
}